// 2025/08/18
// Author: Forever
#include <bits/stdc++.h>
using namespace std;

const int N = 300005;
const int MOD = 998244353;
const int BASE = 131;
int n;
long long B[N];

class SegmentTree {
private:
    struct Node {
        int l, r, len;
        long long hash1, hash2;
        friend Node operator+(const Node& a, const Node& b)
        {
            return { a.l, b.r, a.len + b.len, (a.hash1 * B[b.len] + b.hash1) % MOD, (b.hash2 * B[a.len] + a.hash2) % MOD };
        }
    } tree[N << 2];
    void build(int p, int l, int r)
    {
        tree[p].l = l, tree[p].r = r, tree[p].len = r - l + 1, tree[p].hash1 = tree[p].hash2 = 0;
        if (l == r)
            return;
        int mid = (l + r) >> 1;
        build(p << 1, l, mid);
        build(p << 1 | 1, mid + 1, r);
    }
    void update(int p, int pos)
    {
        if (tree[p].l == tree[p].r) {
            tree[p].hash1 = tree[p].hash2 = 1;
            return;
        }
        int mid = (tree[p].l + tree[p].r) >> 1;
        if (pos <= mid)
            update(p << 1, pos);
        else
            update(p << 1 | 1, pos);
        tree[p] = tree[p << 1] + tree[p << 1 | 1];
    }
    Node query(int p, int l, int r)
    {
        if (tree[p].l >= l && tree[p].r <= r)
            return tree[p];
        int mid = (tree[p].l + tree[p].r) >> 1;
        if (r <= mid)
            return query(p << 1, l, r);
        if (l > mid)
            return query(p << 1 | 1, l, r);
        return query(p << 1, l, r) + query(p << 1 | 1, l, r);
    }

public:
    SegmentTree(int n)
    {
        B[0] = 1;
        for (int i = 1; i <= n; i++)
            B[i] = B[i - 1] * BASE % MOD;
        build(1, 1, n);
    }
    void update(int pos)
    {
        update(1, pos);
    }
    bool check(int a, int b, int c)
    {
        return query(1, a, b).hash1 != query(1, b, c).hash2;
    }
};

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    SegmentTree st(n);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        st.update(x);
        if (i >= 3 && st.check(x - min(x - 1, n - x), x, x + min(x - 1, n - x))) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}